#include <bits/stdc++.h>
// 2025/02/07
// tag:
// Author: Zhang Muen
using namespace std;

int64_t n, m, dist[2001], cnt[2001];
unordered_map<int64_t, int64_t> graph[2001];
bool vis[2001];

bool SPFA(int64_t start)
{
    for (int i = 1; i <= n; i++)
        dist[i] = INT_MAX, cnt[i] = 0, vis[i] = false;
    queue<int> q;
    dist[start] = 0, vis[start] = true;
    q.push(start);
    while (!q.empty()) {
        int u = q.front();
        q.pop(), vis[u] = false;
        for (auto neighbor : graph[u]) {
            int v = neighbor.first, w = neighbor.second;
            if (dist[v] > dist[u] + w) {
                dist[v] = dist[u] + w;
                cnt[v] = cnt[u] + 1;
                if (cnt[v] >= n)
                    return false;
                if (!vis[v])
                    q.push(v), vis[v] = true;
            }
        }
    }
    return true;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--){
        cin >> n >> m;
        for (int i = 1; i <= n; i++)
            graph[i].clear();
        int64_t u, v, w;
        for (int i = 0; i < m; i++) {
            cin >> u >> v >> w;
            if (w >= 0){
                if (graph[u].count(v))
                    graph[u][v] = min(graph[u][v], w);
                else
                    graph[u][v] = w;
                if (graph[v].count(u))
                    graph[v][u] = min(graph[v][u], w);
                else
                    graph[v][u] = w;
            }
            else{
                if (graph[u].count(v))
                    graph[u][v] = min(graph[u][v], w);
                else
                    graph[u][v] = w;
            }
        }
        cout << (SPFA(1) ? "NO" : "YES") << endl;
    }
    return 0;
}